using UnityEngine;
using System.Collections;

/// \class  gkUtilityUV
/// \brief  Mesh uv functions
public class gkUtilityUV 
{
	/// \brief  Apply a sphere cone slice push to the mesh surface
	static public Vector2[] HorizontalPlanarUVMapping(Vector3[] a_rVertices)
	{
		Vector2[] oUVMapping;
		int iCurrentIndex;
		Bounds oBounds;
		float fU;
		float fV;
		
		// Create the Uv mapping
		oUVMapping = new Vector2[a_rVertices.Length];
		
		// Compute the bounds
		oBounds = gkUtilityVertices.ComputeVerticesBounds(a_rVertices);
		
		/// loop through the vertices and project them on the horizontal plane
		iCurrentIndex = 0;
		foreach(Vector3 f3VertexPosition in a_rVertices)
		{
			// Compute the U coordinate
			if(oBounds.size.x != 0.0f)
			{
				fU = (f3VertexPosition.x - oBounds.min.x) / oBounds.size.x;
			}
			else
			{
				fU = 0.0f;
			}
			
			// Compute the V coordinate
			if(oBounds.size.z != 0.0f)
			{
				fV = (f3VertexPosition.z - oBounds.min.z) / oBounds.size.z;
			}
			else
			{
				fV = 0.0f;
			}
			
			// Set the texture coordinate
			oUVMapping[iCurrentIndex] = new Vector2(fU, fV);
			
			iCurrentIndex++;
		}
		
		return oUVMapping;
	} 
}
